Network::Network( const char* in_file ){
	ifstream in;
	in.open( in_file );
	if( !in.is_open() ){
		cerr << "Error in Network class constructor: could not open file " << in_file << endl;
		exit( -1 );
	}
	
	in >> m >> n >> prize;
	
	graph = new Edge**[m];
	for( int i = 0; i < m; ++i )
		graph[i] = new Edge*[m];
	
	for( int i = 0; i < m; ++i )
		for( int j = 0; j < m; ++j )
			graph[i][j] = NULL;
	
	nodes = new struct Node[m];
	for( int i = 0; i < m; ++i ){
		struct Node temp_node;
		in >> temp_node.id >> temp_node.x >> temp_node.y >> temp_node.processing >> temp_node.type;
		temp_node.target_node = -1;
		nodes[i] = temp_node;
	}
	
	for( int k = 0; k < n; ++k ){
		int i, j, bw;
		in >> i >> j;
		
		if( graph[i][j] || graph[j][i] ){
			cerr << "Error in Network class constructor: Duplicated edge" << endl;
			exit(-1);
		}
		in >> bw;
		
		graph[i][j] = new Edge;
		graph[i][j]->bandwidth = bw;
		graph[i][j]->sn_path = NULL;
		
		graph[j][i] = new Edge;
		graph[j][i]->bandwidth = bw;
		graph[j][i]->sn_path = NULL;
	}
}

Network::~Network(){
	delete [] nodes;
	
	for( int i = 0; i < m; ++i )
		for( int j = 0; j < m; ++j )
			if( graph[i][j] != NULL ){
				if( graph[i][j]->sn_path != NULL )
					delete graph[i][j]->sn_path;
				delete graph[i][j];
			}
	
	for( int i = 0; i < m; ++i )
		delete [] graph[i];
	delete [] graph;
}

struct Node* Network::getNodeList(){
	return nodes;
}

Edge*** Network::getGraph(){
	return graph;
}

int Network::getNumberOfNodes(){
	return m;
}

int Network::getNumberOfEdges(){
	return n;
}

Network::Network( int m, int n, int prize ){
	this->m = m;
	this->n = n;
	this->prize = prize;
	
	this->graph = new Edge**[this->m];
	for( int i = 0; i < this->m; ++i )
		this->graph[i] = new Edge*[this->m];
	
	for( int i = 0; i < this->m; ++i )
		for( int j = 0; j < this->m; ++j )
			this->graph[i][j] = NULL;
	
	this->nodes = new struct Node[this->m];
	
}
